﻿using COC.Tools.AI.Motion;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MouseTarget : MonoBehaviour
{
    private Vector3 currMousePos;
    private float dragSpeed = 2f;
    AIBehave[] s;
    List<Transform> list = new List<Transform>();
    public List<Vector3> pathList = new List<Vector3>();
    // Use this for initialization
    void Start()
    {

        s = GameObject.FindObjectsOfType<AIBehave>();
        //calculatePath();

    }
    void startPath(object path)
    {
        iTween.MoveTo(this.gameObject, iTween.Hash( "speed", 10.0f, "path", ((List<Vector3>)path).ToArray(), "delay", .1, "loopType", "pingPong"));

    }
    void calculatePath()
    {
        float times =.01f;
        float angle = 10;
        Vector3 v3 = Vector3.zero;
        GameObject go;
        for (int i = 0; i < 8; i++)
        {
            //v3 = (Quaternion.AngleAxis(Random.Range(-angle, angle), Vector3.up) * new Vector3(Random.Range(-10, 10), 0.3f, Random.Range(-10, 10)));
            v3 =new Vector3(Random.Range(-20, 20), 0.3f, Random.Range(-20, 20));
            pathList.Add(v3);
            go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            go.transform.position = new Vector3(v3.x,0.3f,v3.z);
            go.renderer.material.color = Color.green;
            //times++;

        }

    }
  
    // Update is called once per frame
    void Update()
    {
         Camera.main.transform.LookAt(this.transform);
        /*   if (Input.GetMouseButtonUp(0))
           {
               currMousePos = Vector3.zero;
               currMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
               currMousePos = new Vector3(currMousePos.x, 0, currMousePos.z);
               Debug.Log(currMousePos);
               transform.position = currMousePos;

           }*/
       /* if (Input.GetMouseButtonUp(0))
        {
            currMousePos = Vector3.zero;
            currMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Debug.Log(currMousePos);
            currMousePos = new Vector3(currMousePos.x, 0.3f, currMousePos.z);
            Vector3 move = new Vector3(currMousePos.x * dragSpeed, 0, currMousePos.z * dragSpeed);
            this.transform.Translate(move, Space.World);
            Camera.main.transform.LookAt(this.transform);
            foreach (var t in s)
            {
                t.originPos = this.transform.position;
            }

        }*/
         foreach (var t in s)
         {
             t.originPos = this.transform.position;
         }

    }
}
